const { ListToNode, NodeToList, ListNode, timeL } = require("../utils.js");
/**
 * @param {number[][]} matrix
 * @return {number[]}
 */
var spiralOrder = function (matrix) {
  let resData = []
  const fun2 = (list) => {
    if (!list.length) return [];
    let res = [];
    let yL = list[0].length,
      xL = list.length;
    for (let i = 0; i < yL; i++) {
      res[i] = [];
      for (let y = 0; y < xL; y++) {
        res[i][y] = list[y][yL - 1 - i];
      }
    }
    return res;
  };
  const fun = (list) => {
    if (!list.length) return [];
    resData.push(...list[0])
    fun(fun2(list.splice(1)))
  };
  fun(matrix)
  return resData;
};
let nums = [2,3,1,1,4]
timeL(spiralOrder, [matrix]);
